<?php

require_once __dir__ . "/IWeathers.php";

/*
	The weather class definition
*/
class Wheathers implements IWeathers
{
	private $lang = "fr";
 
	public function get($city, $country)
	{
		try
		{
			set_time_limit(60);
			$url = "http://api.openweathermap.org/data/2.5/weather?q=".$city.",".$country."&units=metric&cnt=7&lang=en";
			$json = @file_get_contents($url);
			
			if($json === FALSE)
			{
				throw new Exception("Failed to access on $url, have you any proxy ?");
			}
			
			$data = json_decode($json, true);
			var_dump($json);
			//Get current Temperature in Celsius
			echo $data['main']['temp']."<br>";
			//Get weather condition
			echo $data['weather'][0]['main']."<br>";
			//Get cloud percentage
			echo $data['clouds']['all']."<br>";
			//Get wind speed
			echo $data['wind']['speed']."<br>";
		}
		catch(Exception $ex)
		{
			var_dump($ex);
		}
		
	}
}

$wheathers = new Wheathers();
$wheathers->get("paris", "fr");

/*
$site="http://www.google.com";
$content =  @file_get_contents($site);

if($content == false)
{
	echo "Get page failed";
}

echo $content;
*/
?>